import json
import unittest
from parameterized import parameterized
from unittest_study.tools import add

# 参数化测试数据，从data_files/add_test_data.txt文件中读取
data_dir= '../data_files/add_test_data.json'
with open(data_dir,'r',encoding='utf-8') as f:
    # 读取json文件中的数据使用json.load()方法,
    contents= json.load(f)
print(contents,type(contents))
data=[tuple(row) for row in contents]
print(data)
class TestAdd(unittest.TestCase):
    @parameterized.expand(data)
    def test_add(self,a,b,expected):
        self.assertEqual(expected,add(a,b))
if __name__ == '__main__':
    unittest.main()